package com.aaa.dao;

import com.aaa.entity.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface MenuDao extends BaseMapper<Menu> {
    @Select("select distinct m.mid,m.mname,m.path,m.lev from users u  join user_role ur on u.id=ur.uid\n" +
            " JOIN role r on ur.rid=r.rid\n" +
            " JOIN role_menu rm on r.rid=rm.rid\n" +
            " JOIN menu m on rm.mid=m.mid where u.id=#{id} and m.lev=1")
    List<Menu> selectOne(Integer id);
    @Select("select distinct m.mid,m.mname,m.path,m.lev from users u  join user_role ur on u.id=ur.uid\n" +
            " JOIN role r on ur.rid=r.rid\n" +
            " JOIN role_menu rm on r.rid=rm.rid\n" +
            " JOIN menu m on rm.mid=m.mid where u.id=#{id} and m.lev=2 and m.pid=#{pid}")
    List<Menu> selectChildren(@Param("id")Integer id, @Param("pid") Integer pid);
    @Select("select distinct m.permit from users u  join user_role ur on u.id=ur.uid\n" +
            "             JOIN role r on ur.rid=r.rid\n" +
            "             JOIN role_menu rm on r.rid=rm.rid\n" +
            "             JOIN menu m on rm.mid=m.mid where u.id=#{id} and m.lev=2")
    List<String> selectPermit(Integer id);
    @Select("select distinct mname,mid from menu where lev=1")
    List<Menu> selectOneMenu();
    @Select("select distinct mname,mid from menu where lev=2 and pid=#{pid}")
    List<Menu> selectTwoMenu(@Param("pid") Integer pid);
    @Select("select  rm.mid from role_menu rm inner join menu m on rm.mid=m.mid \n" +
            "where m.lev=2 and rm.rid=#{rid}")
    List<Integer> selectQxId(Integer rid);
    @Delete("delete from role_menu where rid=#{rid}")
    Integer deleteOldQx(Integer rid);
    @Insert("insert role_menu(rid,mid) values(#{rid},#{mid})")
    Integer insertPermit(@Param("rid") Integer rid,@Param("mid") Integer mid);
}
